.TH std::basic_istream::tellg 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_istream::tellg \- std::basic_istream::tellg

.SH Synopsis
   pos_type tellg();

   Returns input position indicator of the current associated streambuf object.

   Behaves as UnformattedInputFunction, except that gcount() is not affected. After
   constructing and checking the sentry object, if fail() == true, returns
   pos_type(-1). Otherwise, returns rdbuf()->pubseekoff(0, std::ios_base::cur,
   std::ios_base::in).

.SH Parameters

   \fI(none)\fP

.SH Return value

   The current position of the get pointer on success, pos_type(-1) on failure.

.SH Exceptions


   failure if an error occurred (the error state flag is not goodbit) and exceptions()
   is set to throw for that state.

   If an internal operation throws an exception, it is caught and badbit is set. If
   exceptions() is set for badbit, the exception is rethrown.

.SH Example


// Run this code

 #include <iostream>
 #include <sstream>
 #include <string>

 int main()
 {
     std::string str = "Hello, world";
     std::istringstream in(str);
     std::string word;
     in >> word;
     std::cout << "After reading the word \\"" << word
               << "\\" tellg() returns " << in.tellg() << '\\n';
 }

.SH Output:

 After reading the word "Hello," tellg() returns 6

.SH See also

   seekoff   repositions the file position, using relative addressing
   \fB[virtual]\fP \fI(virtual protected member function of std::basic_filebuf<CharT,Traits>)\fP

             repositions the next pointer in the input sequence, output sequence, or
   seekoff   both, using relative addressing
   \fB[virtual]\fP \fI\fI(virtual protected member function\fP of\fP
             std::basic_stringbuf<CharT,Traits,Allocator>)
   seekoff   repositions the next pointer in the input sequence, output sequence, or
   \fB[virtual]\fP both, using relative addressing
             \fI(virtual protected member function of std::strstreambuf)\fP
   seekg     sets the input position indicator
             \fI(public member function)\fP
   tellp     returns the output position indicator
             \fI(public member function of std::basic_ostream<CharT,Traits>)\fP
   seekp     sets the output position indicator
             \fI(public member function of std::basic_ostream<CharT,Traits>)\fP
